package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Information;
import cn.wolfcode.trip.base.query.InformationQuery;
import cn.wolfcode.trip.base.query.MessageQuery;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IInformationService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.plugin2.message.Message;

/**
 * MessageController class
 *
 * @author lishuanwang
 * @date 2019/5/30
 */
@Controller
@RequestMapping("information")
public class InformationController {

    @Autowired
    private IInformationService informationService;

    @RequestMapping("list")
    public String listInformation(@ModelAttribute("qo") InformationQuery qo, Model model){
        model.addAttribute("pageInfo", informationService.listAll(qo));
        return "information/list";
    }

    @RequestMapping("save")
    @ResponseBody
    public JsonResult saveInformation(Information information){
        JsonResult result = new JsonResult();
        try{
            //先把message组装好,因为后台没有登录功能,我们暂时直接设置为1,后台不需要插入
            //message.setUser(UserContext.getCurrentUser());
            informationService.save(information);
        }catch (Exception e){
            result.mark(e.getMessage());
        }
        return result;
    }


}
